package com.ruoyi.web.controller.system;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.RPage;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.vo.WGoodVO;
import com.ruoyi.system.domain.vo.WOrderOpearaGoodVO;
import com.ruoyi.system.domain.vo.WOrderOpearaVO;
import com.ruoyi.system.domain.vo.WOrderVO;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.service.IWGoodService;
import com.ruoyi.system.service.IWOrderOpearaGoodService;
import com.ruoyi.system.service.IWOrderOpearaService;
import com.ruoyi.system.service.IWOrderService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 物料订单操作记录Controller
 * 
 * @author ruoyi
 * @date 2021-12-05
 */
@Api( value="小程序接口" )
@RestController
@RequestMapping("/system/small")
public class WSmallController extends BaseController
{
 
    @Autowired
    private ISysUserService userService;
    @Autowired
    private IWOrderService wOrderService;
    @Autowired
    private IWOrderOpearaService wOrderOpearaService;
    @Autowired
    private IWGoodService wGoodService;
    
    @ApiOperation("小程序 根据customerId查询物料列表")
    @GetMapping("/fList")
    public RPage<WGoodVO> fList(WGoodVO wGood)
    {
    	wGood.setDeptId(getDeptId()); 
    	startPage();
    	List<WGoodVO> list = wGoodService.selectWGoodList(wGood);
    	return getRPageTable(list);
    }

    @ApiOperation("小程序查询工厂下的客户")
    @GetMapping("factory/cutomerList")
    public R<List<SysUser>> cutomerList(SysUser user)
    {
        List<SysUser> list = userService.selectUserList(user);
        return R.success(list);
    }
    
    @ApiOperation("小程序 查询物料订单,传客户id")
    @GetMapping("/listOrder")
    public R<List<WOrderVO>> list(WOrderVO wOrder)
    {
    	LoginUser loginUser = getLoginUser();
    	wOrder.setDeptId(loginUser.getDeptId());
        List<WOrderVO> list = wOrderService.selectWOrderList(wOrder);
        return R.success(list);
    }
    @ApiOperation("小程序查询待盘点来料列表, 传orderId")
    @GetMapping("/listSmallOpera")
    public R<List<WOrderOpearaVO>> listSmall(WOrderOpearaVO wOrderOpeara)
    {
    	wOrderOpeara.setType(1);
        wOrderOpeara.setStatus(2);
        List<WOrderOpearaVO> list = wOrderOpearaService.selectWOrderOpearaList(wOrderOpeara);
        return R.success(list);
    }
    
    @ApiOperation("小程序查询发料详情接口")
    @GetMapping(value = "selectWOrderOpearaSmallById/{id}")
    public R<WOrderOpearaVO>  selectWOrderOpearaSmallById(@PathVariable("id") Long id)
    {
    	R<WOrderOpearaVO> selectWOrderOpearaById = wOrderOpearaService.selectWOrderOpearaById(id);
        return selectWOrderOpearaById;
    }
    
    @ApiOperation("小程序工厂查询生产中物料订单")
    @GetMapping("/list")
    public TableDataInfo selectWOrderList(WOrderVO wOrder)
    {
    	LoginUser loginUser = getLoginUser();
    	wOrder.setDeptId(loginUser.getDeptId());
        startPage();
        wOrder.setOrderStatus(3);
        List<WOrderVO> list = wOrderService.selectWOrderList(wOrder);
        return getDataTable(list);
    }
   
}
